package com.yoke.util;/**
 * Created by jiangzeyin on 2017/2/16.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author jiangzeyin
 * @create 2017 02 16 11:39
 */
public class CmdUtil {
    static Runtime run = Runtime.getRuntime();

    public static String exec(String cmd) throws IOException, InterruptedException {
        System.out.println(cmd);
        Process process = run.exec(cmd);
        InputStream input = process.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(input, "GBK"));
        String line;
        StringBuffer stringBuffer = new StringBuffer();
        while ((line = bufferedReader.readLine()) != null) {
            stringBuffer.append(line).append(System.lineSeparator());
            if ("".equals(line))
                break;
        }
        bufferedReader.close();
        input.close();
        process.destroy();
        return stringBuffer.toString();
    }
}
